﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Vds2465Telegrams;

namespace Vds2465Parser
{
    internal static class GenParse_ReportType_Proprietary
    {
        #region private constants

        internal const byte MsgBlockOnlyValue = 0x70;

        #endregion private constants

        #region internal methods

        internal static byte GenerateByte(ReportType_Proprietary reportTypeProprietary)
        {
            byte resultByte = 0x0;

            // State has 0x1 in Bits 6,5,4
            resultByte += MsgBlockOnlyValue;

            resultByte |= reportTypeProprietary.ProprietaryNibble;            
            return resultByte;
        }

        internal static bool ParseByte(byte byteValue, out byte proprietaryNibble)
        {
            // set arbitrary default value
            proprietaryNibble = 0x00;

            // get only bits 6,5,4
            byte messageBlock = (byte)(byteValue & (byte)0x70);
            if (messageBlock == MsgBlockOnlyValue)
            {
                // get only bits 3,2,1,0
                proprietaryNibble = (byte)(byteValue & (byte)0x0f);
                return true;
            }

            // bits 6,5,4 are wrong
            return false;
        }

        #endregion internal methods
    }
}
